package com.yuanfeng.action.front.index.service;

import com.yuanfeng.action.front.index.dao.IndexDao;
import com.yuanfeng.pojo.Books;
import com.yuanfeng.pojo.Types;
import com.yuanfeng.util.PageBean;

import java.util.List;

/**
 * 首页service实现类
 *
 * @author yuanfeng
 */
public class IndexServiceImpl implements IndexService {

    private IndexDao indexDaoImpl;

    /**
     * spring的setter注入
     *
     * @param indexDaoImpl
     */
    public void setIndexDaoImpl(IndexDao indexDaoImpl) {
        this.indexDaoImpl = indexDaoImpl;
    }

    /**
     * 查询所有类型
     *
     * @return
     */
    public List<Types> queryTypes() {
        return indexDaoImpl.queryTypes();
    }

    /**
     * 查询所有书籍，重载了queryBooks
     *
     * @param typeId
     * @return
     */
    public List<Books> queryBooks(String typeId) {
        return indexDaoImpl.queryBooks(typeId);
    }

    /**
     * 分页部分代码，重载了queryBooks
     *
     * @param typeId
     * @param curPage
     * @param pageSize
     * @return
     */
    public PageBean<Books> queryBooks(String typeId, int curPage, int pageSize) {
        PageBean<Books> pageBean = new PageBean<Books>();
        pageBean.setCurrentPage(curPage);
        pageBean.setPageSize(pageSize);
        pageBean.setTotalCount(indexDaoImpl.queryBooksCount(typeId));
        pageBean.setData(indexDaoImpl.queryBooks(typeId, curPage, pageSize));
        return pageBean;
    }

    /**
     * 根据图书id查询图书
     * @param bookId
     * @return
     */
    public Books queryBook(String bookId) {
        return indexDaoImpl.queryBook(bookId);
    }
}
